<?php if (isset($team)) {  
    //var_dump($team)
    ?>

    

    <div class="row-fluid " style=" margin-bottom: 20px;  margin-top: 20px;">
        <div class="span12">
            <div class="span7">
                <h1><?php echo 'Equipo: '.h($team['Team']['name']); ?></h1>

                <p><small>Created: <?php echo $team['Team']['created']; ?></small></p>

            </div> 

            <div class="span5" align="right">
                <?php echo $this->Form->create(null,array('url'=> 'view/'.$team['Team']['id'].'/find','class'=>'form-search','inputDefaults' => array('label' => false ,'div' => false,'class'=>'input')));
                        echo "<div class='input-append'>";

                        echo $this->Form->input('buscar',array('class'=>'span8 search-query','placeholder'=>'Agregar un usuario')); ?>
                        <button type="submit" class="btn"><i class="icon-search"></i></button>
                <?php echo '</div></form>'; ?>
        
             </div>
            
        <!-- Button to trigger modal -->
<!--        <a data-toggle="modal" href="#addMember" class="btn btn-small btn-inverse " role="button"  ><i class="icon-plus-sign icon-white"></i> Nueva</a>-->
        <!-- Modal -->
        
            <div id="addMember" 
                class="modal hide fade<?php if (isset($users)) echo " in";?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"  aria-hidden="<?php if (isset($users)) echo "true"; else echo "false";?>"
                <?php if (isset($users)) echo 'style="display: block;"'; else echo'style="display: none;"';?>  >

                    <div class="modal-header">
            <!--            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
                        <a class="close " href="<?php echo $this->base;?>/teams/view/<?php echo $team['Team']['id'] ;?>" >x</a>
                        <h3 id="myModalLabel">Elegir Miembro</h3>
                    </div>
                    <div class="modal-body">
                        <?php if (count($users)>0){?>
                        <table class="table table-striped">

                            <tbody > 
                                <?php for ($i=0;$i<count($users);$i++){?>
                                <tr>
                                    <td>
                                        <strong><?php echo $users[$i]['User']['username']; ?></strong>
                                    </td>
                                    <td>
                                        <?php 
                                            echo $this->Form->create('Member',array('url'=> '../members/add/'.$team['Team']['id'].'/1','class'=>'form-inline','inputDefaults' => array('hiddenField' => false,'label' => false ,'div' => false)));
                                            echo $this->Form->hidden('user_id',array('value'=>$users[$i]['User']['id'])); ?>
                                            <button type="submit" class="btn btn-success btn-small" >Agregar</button>
                                            <?php echo '</form>'; ?>

                                    </td>
                                </tr>
                                <?php } ?>
                            </tbody>

                        </table>
                        <?php } else {?>
                            <div class="alert">
                                No se encontraron usuarios.
                            </div>
                        <?php }?>
                    </div>
                    <div class="modal-footer">
                        <div aling="right">
                            <a class="btn" href="<?php echo $this->base;?>/teams/view/<?php echo $team['Team']['id'] ;?>" >Cancelar</a>
                        </div>

                    </div>
            </div>
            
            
            <!--USO DEL SELECT-->
<!--            <div class="span5" align="right">
                <?php echo $this->Form->create('Member',array('url'=> '../members/add/'.$team['Team']['id'].'/1','class'=>'form-inline','inputDefaults' => array('label' => false ,'div' => false,'class'=>'input')));

                    $arrOptions=array();
                    if  (isset($users)){
                        var_dump($users);
                        for ($i=0;$i<count($users);$i++){
                            $idU=$users[$i]['User']['id'];
                            $nameU=$users[$i]['User']['username'];
                            $arrOptions[$idU]=$nameU;
                        }
                    }
                    echo $this->Form->input('user_id', array(
                                'options' => $arrOptions,
                                'empty' => '(choose one)'
                            ));
                    echo "    ";
                    ?>
                    <button type="submit" class="btn" >Agregar</button>
                     <?php echo '</form>'; ?>
                    <?php
            //        $options = array(
            //        'label' => 'Agregar',
            //        'div' => array(
            //            'class' => 'btn',
            //        )
            //        );
            //        echo $this->Form->end($options);
                    ?>
            </div>            -->
        </div>
        <div class="span12">
            
        </div>
    </div>
    
        
        
    <!--    MEMBERS!-->
    <?php if (count($team['Member'])>0)  {
        $members=$team['Member'];
        for ($i = 0; $i < count($members); $i++) { ?>

            <div class="team-member-box" id="team_member_19218">

                <ul class="nav nav-pills pull-right">
                   
                    <li>
                        
                        <?php echo $this->Form->postLink(
                                    '<i class="icon-trash"></i>', //le image
                                    '/members/delete/'.$members[$i]['user_id'].'/'.$members[$i]['team_id'], //,le url
                                    array('escape' => false,'confirm' => 'Are you sure?','class' => 'nav-pills'));

                         ?>   
                        
                    </li>
               
                </ul>
                <?php /*echo '/members/delete/'.$members[$i]['user_id'].'/'.$members[$i]['team_id']; */?>

                <span class="member-avatar">
                    <?php echo $this->Html->image('icons/32x32/user.png', array('alt' => $members[$i]['name'], 'border' => '0')) ;?>
           
                </span>
                <b>
                </b>
                    <?php echo $members[$i]['name'];?>

                <div class="team-member-box-email">
                    <br/><?php
                    if ($members[$i]['state']==1)
                        echo '<span class="label label-success">Creador</span>';
                    if ($members[$i]['state']==0)
                        echo '<span class="label label-default">Invitado</span>';
                    if ($members[$i]['state']==2)
                        echo '<span class="label label-info">Colaborador</span>';
                    
                    //var_dump($members[$i]);
                    ?>

                </div>
            </div>

    <?php  }
        } else { ?>
        <div class="alert">
            <button type="button" class="close" data-dismiss="alert">×</button>
            No ha ingresado ningún miembro.
        </div>
    <?php }
    if (isset($users))
        echo '<div class="modal-backdrop fade in"></div>';
    
    ?>
    
   
    <?php } else {?>
    <br/>
    <div class="alert alert-info">
        Error de acceso.
    </div>
<?php }?>


